#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<errno.h>

int main()
{
    if(mkfifo("my_fifo",0664)==-1)
    {
        if(errno != EEXIST)
        {
            perror("fail to mkfifo");
            exit(-1);
        }
    }
    #if 0
    //只有读端，会在open处就阻塞
    printf("********************\n");
    int fd = open("my_fifo",O_RDONLY);
    char buf[32] =  "";
    printf("--------------------\n");
    if(read(fd,buf,sizeof(buf)) == -1)
    {
        perror("fail to read");
        exit(-1);
    }
    printf("buf = %s\n",buf);
    #endif

    #if 1
    //只有写端，会在open处就阻塞
    printf("********************\n");
    int fd = open("my_fifo",O_WRONLY);
    printf("--------------------\n");
    if(write(fd,"hello world",strlen("hello world")) == -1)
    {
        perror("fail to write");
        exit(-1);
    }
    printf("写入成功\n");
    #endif
    return 0;
}